import axios from 'axios'

// 创建axios实例
const instance = axios.create({
  baseURL: 'https://restapi.amap.com/v3',
  timeout: 3000,
})

// 设置响应拦截器
instance.interceptors.response.use(
  (res) => {
    if (res.data?.status === '1') {
      return res.data
    } else {
      return Promise.reject(new Error('API请求失败'))
    }
  },
  (error) => {
    return Promise.reject(new Error('请求失败'))
  }
)

export default instance
